<?php
use yii\helpers\Url;
use yii\Web\View;
use app\assets\MediaListAsset;
MediaListAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  \Yii::t('media-list', 'Media List'),
  \Yii::t('common', 'Data')
];
$jsMsgs = $this->context->loadJsMsgs([
  'table',
  'mediaList',
  'listOp'
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('media-list', 'Media Management')?>
    <small><?=\Yii::t('media-list', 'Media List')?></small>
    <!-- <div class="btn-group pull-right" role="group" aria-label="...">
      <a href="<?= Url::to(['black-white-list']);?>" class="btn btn-sm btn-success" data-loading-text="<i class='fa fa-spinner fa-spin'></i> 加载中..." id="new-operate-btn">
        <i class="fa fa-plus-circle"></i>
        黑白名单管理
      </a>
    </div> -->
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading"> 
    <i class="fa fa-table"></i>
    <?=\Yii::t('media-list', 'Media List')?>
    <ul class="list-inline list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
  <div class="panel-body">
    <div class="panel panel-dotted">
      <div class="panel-heading">
        <h4>
          <i class="fa fa-filter"></i>
            <?=\Yii::t('common', 'Search Condition')?>
        </h4>
      </div>
      <div class="panel-body">
        <div class="form-horizontal" id="filter-frm">
          <div class="form-group <?php if (!$_SESSION['is_root']) echo 'hidden';?>">
            <label class="col-sm-1 control-label pr0">
              <?=\Yii::t('media-list', 'Market')?>：
            </label>
            <div class="col-sm-11">
              <label class="radio-inline active">
                <input data-column="2" type="radio" name="filter-channel" value="" checked=""> <?=\Yii::t('media-list', 'All')?>
              </label>
              <?php
                $out = '';
                foreach ($adNetWorks as $adNetWork) {
                  $name = $adNetWork['name'];
                  $out .= <<<FINE
                    <label class="radio-inline">
                      <input data-column="2" type="radio" name="filter-channel" value="$name"> $name
                    </label>   
FINE;
                }
                echo $out;
              ?>
<!--               <label class="radio-inline">
                <input data-column="2" type="radio" name="filter-channel" value="<?=\Yii::t('common', 'ValueMaker')?>"> <?=\Yii::t('common', 'ValueMaker')?>
              </label> --><!-- 
              <label class="radio-inline">
                <input data-column="2" type="radio" name="filter-channel" value="Acelink"> Acelink
              </label>
              <label class="radio-inline">
                <input data-column="2" type="radio" name="filter-channel" value="Vivaki"> Vivaki
              </label> -->
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-1 control-label pr0">
              <?=\Yii::t('media-list', 'Traffic')?>：
            </label>
            <div class="col-sm-11">
              <label class="radio-inline active">
                <input data-column="3" type="radio" name="filter-traffic" value="" checked=""> <?=\Yii::t('media-list', 'All')?>
              </label>
			  <?php
				$pc = <<<FINE
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="PC-Display"> PC-Display
              </label>
FINE;
				if (in_array('1', $_SESSION['traffic_slot'])) echo $pc;
			  ?>
			  <?php
				$pv = <<<FINE
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="PC-Video"> PC-Video
              </label>
FINE;
				if (in_array('2', $_SESSION['traffic_slot'])) echo $pv;
			  ?>
			  <?php
				$mm = <<<FINE
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="Mobile-Web"> Mobile-Web
              </label>
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="Mobile-iOS-Display"> Mobile-iOS-Display
              </label>
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="Mobile-Android-Display"> Mobile-Android-Display
              </label>
FINE;
				if (in_array('3', $_SESSION['traffic_slot'])) echo $mm;
			  ?>
			  <?php
				$mv = <<<FINE
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="Mobile-iOS-Video"> Mobile-iOS-Video
              </label>
              <label class="radio-inline">
                <input data-column="3" type="radio" name="filter-traffic" value="Mobile-Android-Video"> Mobile-Android-Video
              </label>
FINE;
				if (in_array('4', $_SESSION['traffic_slot'])) echo $mv;
			  ?>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="panel panel-dotted">
      <div class="panel-heading"> 
        <h4>
          <i class="fa fa-table"></i>
          <?=\Yii::t('media-list', 'Media List')?>
          <ul class="list-inline list-unstyled pull-right">
            <li>
              <a class="data-table-refresh" href="#" title="<?=\Yii::t('common', 'Click to refresh data')?>">
                <i class="fa fa-refresh"></i>
              </a>
            </li>
            <li>
              <a href="#">
                <i class="fa fa-chevron-up"></i>
              </a>
            </li>
          </ul>
        </h4>
      </div>
      <div class="panel-body">
        <div id="list-loading-wrap" class="local-loading-wrap"></div>
        <div class="table-responsive">
          <table class="table table-hover table-striped table-bordered table-condensed" id="data-table" data-tag="vm-adserver.media-adspace-list">
            <thead class="heading">
              <tr>
                <th data-resizable-column-id="id" data-search="on" data-filter="on">ID</th>
                <th data-resizable-column-id="name" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Name')?></th>
                <th data-resizable-column-id="belongChannel" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Market')?></th>
                <th data-resizable-column-id="trafficType" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Traffic')?></th>
                <th data-resizable-column-id="size" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Size')?></th>
                <th data-resizable-column-id="type" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Category')?></th>
                <th data-resizable-column-id="allowFormat" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Format')?></th>
                <th data-resizable-column-id="systemType" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'System Type')?></th>
                <th data-resizable-column-id="position" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Form')?></th>
                <th data-resizable-column-id="price" data-search="on" data-filter="on"><?=\Yii::t('media-list', 'Price')?>(CPM/￥)</th>
              </tr>
            </thead>
            <tbody>
              <tr role="row">
                <td class="text-center dataTables_empty" colspan="10"><?=\Yii::t('site', 'No Records')?></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>    
  </div>
</div>
<?php
  $url = Url::to(['get-adspaces']);
  $filterStatus = $filter;
  // $url = Yii::getAlias('@web') . '/response/mediaList/mediaListDataList.php';
  $this->registerJs("VAM.setVar('MEDIA_LIST_DATA_LIST', '$url')", View::POS_HEAD);
  $this->registerJs("VAM.setVar('LIST_FILTER_STATUS', '$filterStatus')",View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/mediaList/mediaList.js"]);
  });
</script>